package com.doubao.common.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Bean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;

/**
 * 自定义Nacos配置类
 *
 * 注意：这个类创建的Bean已重命名，避免与Spring Cloud Alibaba中的Bean冲突
 */
@Configuration
@EnableConfigurationProperties
public class NacosConfig {

    @Bean(name = "customNacosDiscoveryProperties")
    @ConfigurationProperties(prefix = "spring.cloud.nacos.discovery")
    public NacosDiscoveryProperties customNacosDiscoveryProperties() {
        return new NacosDiscoveryProperties();
    }

    @Bean(name = "customNacosConfigProperties")
    @ConfigurationProperties(prefix = "spring.cloud.nacos.config")
    public NacosConfigProperties customNacosConfigProperties() {
        return new NacosConfigProperties();
    }

    // Nacos属性类
    public static class NacosDiscoveryProperties {
        private String serverAddr;
        private String namespace;

        // getter和setter
        public String getServerAddr() {
            return serverAddr;
        }

        public void setServerAddr(String serverAddr) {
            this.serverAddr = serverAddr;
        }

        public String getNamespace() {
            return namespace;
        }

        public void setNamespace(String namespace) {
            this.namespace = namespace;
        }
    }

    public static class NacosConfigProperties {
        private String serverAddr;
        private String namespace;
        private String fileExtension;

        // getter和setter
        public String getServerAddr() {
            return serverAddr;
        }

        public void setServerAddr(String serverAddr) {
            this.serverAddr = serverAddr;
        }

        public String getNamespace() {
            return namespace;
        }

        public void setNamespace(String namespace) {
            this.namespace = namespace;
        }

        public String getFileExtension() {
            return fileExtension;
        }

        public void setFileExtension(String fileExtension) {
            this.fileExtension = fileExtension;
        }
    }
}